package com.huangkailong.designpattern.builder;

import lombok.Data;

/**
 * UserInfo 建造者模式构建实现.
 *
 * @author huangkl
 * @since 1.0.0
 */
@Data
public class UserInfo {
    private String username;
    private String password;
    private Integer age;
    private String address;
    private String phone;
    private String email;

    public static UserInfoBuilder builder() {
        return new UserInfoBuilder();
    }

    public static class UserInfoBuilder {
        private String username;
        private String password;
        private Integer age;
        private String address;
        private String phone;
        private String email;

        /**
         * 根据 {@link UserInfoBuilder} 构建出 {@link UserInfo} 对象
         *
         * @return {@link UserInfo}
         */
        public UserInfo build() {
            UserInfo userInfo = new UserInfo();
            userInfo.setUsername(username);
            userInfo.setPassword(password);
            userInfo.setAge(age);
            userInfo.setAddress(address);
            userInfo.setPhone(phone);
            userInfo.setEmail(email);
            return userInfo;
        }

        public UserInfoBuilder username(String username) {
            this.username = username;
            return this;
        }

        public UserInfoBuilder password(String password) {
            this.password = password;
            return this;
        }

        public UserInfoBuilder age(Integer age) {
            this.age = age;
            return this;
        }

        public UserInfoBuilder address(String address) {
            this.address = address;
            return this;
        }

        public UserInfoBuilder phone(String phone) {
            this.phone = phone;
            return this;
        }

        public UserInfoBuilder email(String email) {
            this.email = email;
            return this;
        }
    }
}
